package com.supermap.dataservice.cloud.annualService;

import com.supermap.dataservice.cloud.annualService.entity.AnnualServiceDo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @version v1.0.0
 * @Author:zhoujian
 * @Desciption:周年服务方案DAO
 * @date 2019-04-11 18:00
 */
@Mapper
public interface AnnualServiceMapper {

    @Select("SELECT tasp.id as productId,tasp.product_title as title , tasp.creater , \n" +
            "date_format( tasp.create_time,'%Y-%m-%d %H:%i:%S') as createTime,\n" +
            "tasp.updater,\n" +
            "date_format(tasp.update_time,'%Y-%m-%d %H:%i:%S') as updateTime\n" +
            "FROM t_annual_service_crop tasc, t_annual_service_area tasa,t_annual_service_product tasp\n" +
            "WHERE tasc.product_id = tasa.product_id AND tasc.product_id = tasp.id AND tasc.cid in (\n" +
            "SELECT crop\n" +
            "FROM t_user_crop t\n" +
            "WHERE t.userid=#{userId}) \n" +
            "AND tasa.area_code=#{areaCode}\n" +
            "and tasp.product_status = 1\n" +
            "order by tasp.create_time")
    public List<Map<String,Object>> selectProductListByUserAndAreaCode(@Param("userId") String userId , @Param("areaCode") String areaCode);


    @Select("SELECT t.pid,t.growth_period as growthPeriod, t.agri_indicators as agriIndicators,\n" +
            "t.important_weather as importantWeather ,t.focus , t.management_measure as managementMeasure,\n" +
            "t.service_product_type as serviceProductType,t.start_date as startDate,t.end_date as endDate,\n" +
            "t.publish_mode as publishMode,date_format( t.create_time,'%Y-%m-%d %H:%i:%S') as createTime,t.creater," +
            "date_format( t.update_time,'%Y-%m-%d %H:%i:%S') as updateTime,\n" +
            "t.updater,t.`status`,t.`order`\n" +
            "FROM t_annual_service_product_details t\n" +
            "WHERE t.pid = #{productId}\n" +
            "and t.status = 1 \n "+
            "order by `order`")
    public List<AnnualServiceDo> selectProductDetailsByProductId(@Param("productId") Integer productId);

}